package com.cd.javacxy.common.model.vo;


import com.cd.javacxy.common.model.enums.ResponseCode;
import lombok.Builder;
import lombok.Data;

/**
 * @author UserC
 */
@Builder
@Data
public class AjaxResponse<T> {
    private int code;
    private String errorMsg;
    private T data;

    public static <T> AjaxResponse<T> ok(T t) {
        return AjaxResponse.<T>builder()
                .code(ResponseCode.SUCCESS.getCode())
                .data(t)
                .build();
    }

    public static <T> AjaxResponse<T> ok() {
        return AjaxResponse.<T>builder()
                .code(ResponseCode.SUCCESS.getCode())
                .build();
    }

    public static <T> AjaxResponse<T> error(String msg) {
        return AjaxResponse.<T>builder()
                .code(ResponseCode.SERVERERROR.getCode())
                .errorMsg(msg)
                .build();
    }

    public static <T> AjaxResponse<T> error(int code, String msg) {
        return AjaxResponse.<T>builder()
                .code(code)
                .errorMsg(msg)
                .build();
    }
}
